package com.yunliuchain.examination.common.res;



;import com.alibaba.fastjson.JSON;
import com.yunliuchain.examination.common.constant.MsgCode;

/**
 * api 层返回的结果
 * 
 * @author chen.jiaming
 *
 */
public class ApiResult<T> {
	private T data;

	private String code;

	private boolean isSuccess;

	private String msg;

	public ApiResult() {
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public boolean isSuccess() {
		return isSuccess;
	}

	public void setSuccess(boolean success) {
		isSuccess = success;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public static ApiResult  success(){
		return ApiResult.success(null);
	}

	public static ApiResult  success(Object data){
		ApiResult apiResult = new ApiResult();
		apiResult.setSuccess(true);
		apiResult.setData(data);
		apiResult.setCode(MsgCode.SUCCESS);
		apiResult.setMsg("操作成功");
		return apiResult;
	}

	public static ApiResult  fail(String message){
		ApiResult apiResult = new ApiResult();
		apiResult.setSuccess(false);
		apiResult.setCode(MsgCode.ERROR);
		apiResult.setMsg(message);
		return apiResult;
	}

	public static ApiResult  fail(String code, String message){
		ApiResult apiResult = new ApiResult();
		apiResult.setSuccess(false);
		apiResult.setCode(code);
		apiResult.setMsg(message);
		return apiResult;
	}


	@Override
	public String toString() {
		return JSON.toJSONString(this);
	}
}
